// page_two/sisdj/sisdj.js
let app = getApp()
let yuming = app.globalData.yuming;
var shuzong = [];
var shu = [];
const request = require('../../config/request');
Page({
  ...request,
  /**
   * 页面的初始数据
   */
  data: {
    yuming: yuming,
    heights: "",
    title: '四实登记',
    gongwu: false,
    // ssdjList: [{
    //     name: '王国栋',
    //     phone: '15953435435',
    //     sfzh: '330621198712163215',
    //     sfzzm: 'static/applet/images/linshi/sfzzm.png',
    //     sfzfm: 'static/applet/images/linshi/sfzfm.png'
    //   },
    //   {
    //     name: '王国栋',
    //     phone: '15953435435',
    //     sfzh: '330621198712163215',
    //     sfzzm: 'static/applet/images/linshi/sfzzm.png',
    //     sfzfm: 'static/applet/images/linshi/sfzfm.png'
    //   },
    //   {
    //     name: '王国栋',
    //     phone: '15953435435',
    //     sfzh: '330621198712163215',
    //     sfzzm: 'static/applet/images/linshi/sfzzm.png',
    //     sfzfm: 'static/applet/images/linshi/sfzfm.png'
    //   }
    // ],
    ssdjList: [],
    page: 1,
    gongwu: false,
    date: '开始时间', //开始
    endTime: '结束时间',
    starTime: '',
    endTimes: '',
    istime: false, //弹出时间筛选
  },
  tan() {
    this.setData({
      istime: !this.data.istime
    })
  },
  xinzeng(e) {
    wx.navigateTo({
      url: '/page_two/sisdjadd/sisdjadd',
    })
  },
  getssdjList() {
    let that = this;
    wx.showLoading({
      title: '加载中',
      icon: 'none'
    })
    this.myRequest(yuming + 'Shopthat/four_realms_list', {
      shopId: wx.getStorageSync('shopId'),
      page: that.data.page,
      start_time: that.data.starTime,
      end_time: that.data.endTimes
    }, 'POST').then(res => {
      wx.hideLoading();
      if (res.data.code == 200) {
        shu = res.data.data;
        if (that.data.page != 1) {
          if (shu.length != 10) {
            that.setData({
              gongwu: true
            })
          }
        }
        that.setData({
          ssdjList: shuzong.concat(shu)
        })
      }
    })
  },
  // 查看更多
  lookmore() {
    shuzong = this.data.ssdjList
    this.setData({
      page: (this.data.page) + 1
    })
    this.getssdjList()
  },
  //点击放大
  fangda(e) {
    var img = e.currentTarget.dataset.img;
    wx.previewImage({
      urls: [img]
    })
  },
  // 选择开始时间
  bindDateChange: function (e) {
    this.setData({
      date: e.detail.value,
      starTime: e.detail.value
    })
  },
  // 选择结束时间
  endTime: function (e) {
    this.setData({
      endTime: e.detail.value,
      endTimes: e.detail.value,
    })
  },
  que() {
    this.setData({
      istime: !this.data.istime
    })
    this.getssdjList();
  },
  // 删除
  delete(e) {
    let that = this
    let id = e.currentTarget.dataset.id
    wx.showModal({
      title: '您确定要删除吗？',
      cancelText: '取消',
      confirmText: '确定',
      success: function (res) {
        if (res.confirm) {
          console.log("确定")
          that.dele(id)
        } else {
          console.log("取消")
        }
      }
    })
  },
  // 删除接口
  dele(id) {
    let that = this
    this.myRequest(yuming + 'Shopthat/four_realms_del', {
      id
    }, "POST").then(res => {
      wx.showToast({
        title: res.data.msg,
        icon: 'none'
      })
      if (res.data.code == 200) {
        shuzong = [];
        shu = [];   
        this.setData({
          gongwu: false,
          page: 1
        })
        that.getssdjList();
      }
    })
  },
  backs() {
    wx.navigateBack({
      delta: 0
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    shuzong = [];
    shu = [];
    this.setData({
      heights: wx.getMenuButtonBoundingClientRect().top + 5,
      shopType: options.shopType,
      title: options.title
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getssdjList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
})